Page({
  data: {
    color: '#fff',
    brightness: 100,
    showSlider: true,
    showBackBtn: true,
    hideTimer: null
  },
  onLoad(query) {
    this.setData({
      color: decodeURIComponent(query.color || '#fff'),
      brightness: Number(query.brightness) || 100,
      showSlider: true,
      showBackBtn: true
    });
    this.startAutoHide();
  },
  startAutoHide() {
    if (this.data.hideTimer) clearTimeout(this.data.hideTimer);
    this.data.hideTimer = setTimeout(() => {
      this.setData({ showSlider: false, showBackBtn: false });
    }, 1000);
  },
  toggleSlider(e) {
    if (e && e.target && e.target.dataset && e.target.dataset.btn) return;
    if (this.data.hideTimer) clearTimeout(this.data.hideTimer);
    this.setData({ showSlider: true, showBackBtn: true });
    this.startAutoHide();
  },
  onBrightnessChanging(e) {
    this.setData({ brightness: e.detail.value });
    if (this.data.hideTimer) clearTimeout(this.data.hideTimer);
    this.startAutoHide();
  },
  onBrightnessChange(e) {
    this.setData({ brightness: e.detail.value });
    // 不自动隐藏，交由toggleSlider控制
  },
  goBack() {
    wx.navigateBack();
  },
  onUnload() {
    if (this.data.hideTimer) clearTimeout(this.data.hideTimer);
  }
}); 